using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class PersonnelAdministration_ProfileSettings : System.Web.UI.Page
{
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            MembershipUser currentUser = Membership.GetUser();
            lblUserName.Text = currentUser.UserName;
            tbUserName.Text = currentUser.UserName;
            tbEmail.Text = currentUser.Email;
            SetViewAccordingToRole(currentUser.UserName);
        }
    }
    private void SetViewAccordingToRole(string userName)
    {
        if (Roles.IsUserInRole(userName, "Doctors"))
        {
            mvUserInfo.SetActiveView(vDoctor);
            dvDoctors.DataBind();
        }
        else if (Roles.IsUserInRole(userName, "Nurses"))
        {
            mvUserInfo.SetActiveView(vNurse);
            dvNurses.DataBind();
        }
        else if (Roles.IsUserInRole(userName, "Attendants"))
        {
            mvUserInfo.SetActiveView(vAttendant);
            dvAttendants.DataBind();
        }

    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        DetailsView currentDetailsView = null;
        if (mvUserInfo.ActiveViewIndex == 0)
        {
            currentDetailsView = dvDoctors;
        }
        else if (mvUserInfo.ActiveViewIndex == 1)
        {
            currentDetailsView = dvNurses;
        }
        else if (mvUserInfo.ActiveViewIndex == 2)
        {
            currentDetailsView = dvAttendants;
        }

        //in case of administrators only
        if (currentDetailsView != null)
        {
            currentDetailsView.UpdateItem(true);
        }
    }
    
    protected void odsControl_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
    {
        object userId = Membership.GetUser().ProviderUserKey;
        e.InputParameters["UserId"] = userId;
    }
}
